﻿@model RBS.Web.Models.OrderViewModel
@{
    ViewBag.Title = "优惠信息";
    Layout = "~/Views/Shared/_UserLayout.cshtml"; 
}

 
<!--内容-->
@{
    @Html.Partial("_Location");
}
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)  
     @Html.HiddenFor(model => model.OrderModel.Id);
    @Html.HiddenFor(model => model.OrderModel.H_Id);
    @Html.HiddenFor(model => model.OrderModel.DineTable);
    @Html.HiddenFor(model => model.OrderModel.U_Id); 
    @Html.HiddenFor(model => model.UserIntegration); 
    <div class="tab-content">
        <dl>
            <dt>应付金额：</dt>
            <dd>@Html.TextBoxFor(model => model.Seetlement.Amount, null, new { @class = "input small jine", @readonly = "readonly" })元
            </dd> 
        </dl>
     @{
                                                   if (Model.User != null)
                                                   {
             
             <dl>
                 <dt>会员积分：</dt>
                 <dd>@Model.UserIntegration 积分（可抵用 @String.Format("{0}", Model.UserIntegration / 100.00) 元） </dd>  
             </dl> 
             <dl>
                 <dt>积分抵扣：</dt>
                 <dd>@Html.TextBoxFor(model => model.Seetlement.JF, "0", new { @class = "input small jine" }) 分 </dd>  
             </dl>
             <dl>
                 <dt>优惠券使用：</dt>
                 <dd>
                     @Html.HiddenFor(model => model.Seetlement.AdvertisId) 
                     @{
                         <ul>
                             @if (Model.UserDeed == null)
                             {
                                 <li>无优惠卷信息</li>
                             }
                             else
                             {
                                 foreach (var row in Model.UserDeed)
                                 {
                                     if (row.DeedType == 1)
                                     {
                                         <li> 
                                             <input id="@row.Id" type="checkbox"  name="SendFood" datatype="max2" value="@row.Id" /> 
                                             <label for="@row.Id">@row.Crowd [送采券]</label> 
                                         </li>
                                     }
                                     if (row.DeedType == 2)
                                     {
                                         <li> 
                                             <input id="@row.Id" type="checkbox"  name="Consumption" datatype="max2" value="@row.Id" /> 
                                             <label for="@row.Id">@row.Crowd  [消费券]</label> 
                                         </li>
                                     }
                                     if (row.DeedType == 3)
                                     {
                                         <li> 
                                             <input id="@row.Id" type="checkbox"  name="Advertis" datatype="max2" value="@row.Id" /> 
                                             <label for="@row.Id">@row.Crowd  [广告券]</label> 
                                         </li>
                                     }
                                 }
                             } 
                         </ul>
                     } 
                 </dd>
             </dl>
                                                   } 
           <script>
               $(function () {
                   //用户积分
                   $('#Seetlement_JF').change(function () {
                       var a = $("#Seetlement_OrderAmount").val();
                       var userIntegration = $("#UserIntegration").val();
                       //alert(userIntegration);
                       var b = $(this).val();
                       var aa = a * 100;
                       if (parseInt(b) > parseInt(userIntegration)) {
                           alert("您当前积分为：" + userIntegration);
                           $(this).val(userIntegration);
                       }
                       if (b > aa) {
                           alert("积分最大输入为：" + aa);
                           $(this).val(aa);
                       }
                       $("#Seetlement_Amount").focus();
                   });
                   //用户优惠券
                   $(':checkbox[name="chkItem"]').click(function () {
                       $("#Seetlement_Amount").focus();
                   });
                   $("#Seetlement_Amount").focus(function () {
                       var theOrderAmount = $("#Seetlement_OrderAmount").val();
                       var ccccc = parseFloat($('#Seetlement_JF').val()) / 100;
                       var youhuiquan = 0;
                        for (var i = 0; i < this.form.SendFood.length; i++) {
                           if (this.form.SendFood[i].type == 'checkbox') {
                               if (this.form.SendFood[i].checked) {
                                   youhuiquan += parseFloat(this.form.SendFood[i].value);
                               }
                           }
                        }
                        for (var i = 0; i < this.form.SendFood.length; i++) {
                            if (this.form.SendFood[i].type == 'checkbox') {
                                if (this.form.SendFood[i].checked) {
                                    youhuiquan += parseFloat(this.form.SendFood[i].value);
                                }
                            }
                        }
                       this.value = parseFloat(theOrderAmount) - ccccc - youhuiquan;
                       $("#Seetlement_PaidAmount").focus();
                   }); 
                   $('#Seetlement_DisAmount').change(function () {
                       $("#Seetlement_PaidAmount").focus();
                   });

                   $("#Seetlement_PaidAmount").focus(function () {
                       var amount = parseFloat($("#Seetlement_Amount").val());
                       var disAmount = parseFloat($("#Seetlement_DisAmount").val());
                       this.value = amount - disAmount;
                       $("#Seetlement_GiveAmount").focus();
                   });

                   $('#Seetlement_RecAmount').change(function () {
                       $("#Seetlement_GiveAmount").focus();
                   });
                   $("#Seetlement_GiveAmount").focus(function () {
                       var paidAmount = parseFloat($("#Seetlement_PaidAmount").val());
                       var recAmount = parseFloat($("#Seetlement_RecAmount").val());
                       this.value = recAmount - paidAmount;
                   }); 
                   //金额不能小于0
                   $.extend($.Datatype, {
                       "ck": function (gets, obj, curform, regxp) {
                           if (parseInt(gets) < 0) {
                               return false;
                           }
                           return true;
                       },
                       "max2": function (gets, obj, curform, regxp) {
                           var atmax = 1,
                               numselected = curform.find("input[name='" + obj.attr("name") + "']:checked").length;

                           if (numselected > atmax) {
                               return "每种优惠券最多只能选择" + atmax + "项！";
                           }
                           return true;
                       }
                   });
               });
                 
            </script>
     }
  </div>
    <!--/内容--> 
    <!--工具栏-->
    <div class="page-footer">
        <div class="btn-list">
            <input type="submit" value="提交保存" class="btn" />
            <input name="btnReturn" type="button" value="返回上一页" class="btn yellow" onclick="javascript: history.back(-1);" /> 
        </div>
        <div class="clear"></div>
    </div>
    <!--/工具栏--> 
}










